package com.app.web.front.controller;

import com.app.util.AjaxResult;
import com.app.util.DateUtils;
import com.app.web.BaseController;
import com.app.web.front.model.Favorite;

public class FavoriteController extends BaseController{
	
	
	public void addFavorite(){
		AjaxResult result = new AjaxResult(1,"收藏成功");
		try {
			
			Favorite favorite = this.getModel(Favorite.class).setAttrs(this.getParamMap());
			favorite.set("user_id", this.getCurrUser().get("id"));
			favorite.set("create_time", DateUtils.getCurrDateTime());
			favorite.save();
		} catch (Exception e) {
			e.printStackTrace();
			result.setFailure("收藏失败:"+e.getMessage());
		}
		
		this.renderJson(result.toJson());
	}
	
	public void cancelFavorite(){
		AjaxResult result = new AjaxResult(1,"取消成功");
		try {
			int typeId = this.getParaToInt("type_id");
			String type = this.getPara("type", "");
			Favorite.dao.deleteByTypeId(typeId, type);
		} catch (Exception e) {
			e.printStackTrace();
			result.setFailure("取消失败:"+e.getMessage());
		}
		
		this.renderJson(result.toJson());
		
	}
}
